<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        * {
            font-size: 28px
        }
    </style>
</head>

<body>
    <div>测试复杂请求界面</div>
    <button id="ajaxBtn">AjAX局部刷新</button>
    <div class="ajax-change" id="responseDiv">change区域</div>
    <script>
        function test() {
            var xhrObj = new XMLHttpRequest();
            xhrObj.onreadystatechange = function () {

                if (xhrObj.readyState == 4 && xhrObj.status == 200) {
                    console.log(xhrObj.responseText);
                    console.log(xhrObj.getAllResponseHeaders())
                    document.getElementById("responseDiv").innerHTML = xhrObj.responseText;
                }
            };
            xhrObj.open("post", "http://127.0.0.1:3000/report", true);
            xhrObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhrObj.setRequestHeader('X-PINGOTHER', 'pingpong');
            xhrObj.send("xhr=1");
        }

        document.getElementById("ajaxBtn").addEventListener("click", function () {
            test();
        });
    </script>
</body>

</html>